﻿//_______________________________________________________________________________________________________________________
// Copy Right (c) 2010, 2011 SapiensIT Consulting GmbH, all rights reserved
//_______________________________________________________________________________________________________________________
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT
// NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//_______________________________________________________________________________________________________________________
// PROJECT:     sapiens.at.SharePoint (SharePoint 2010/V4)
//_______________________________________________________________________________________________________________________
// VERSION:     2.0
//_______________________________________________________________________________________________________________________
// DESCRIPTION: 
//_______________________________________________________________________________________________________________________
// LICENSE:     Different licens Types apply to different file types:
//               - Source code files are governed by the MICROSOFT PUBLIC LICENSE (Ms-PL)
//               - Binary files are governed by MSDN CODE GALLERY BINARY LICENSE
//               - Documentation files are governed by CREATIVE COMMONS ATTRIBUTION 3.0 LICENSE
//
//               The licenses can be found at the projects source location.
//               If you do not agree, don't use it!
// 
//_______________________________________________________________________________________________________________________
// Start SharePoint Branding, visit http://www.cliggin.com! Visit us on http://www.sapiens.at! Tell your friends! 
//_______________________________________________________________________________________________________________________
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sapiens.at.SharePoint.Utils
{
    /// <summary>
    /// Helper methods for various SharePoint tasks.
    /// </summary>
    public static class Tools
    {
        /// <summary>
        /// Removes characters from a string that can't exist in an URL.
        /// </summary>
        /// <param name="input">The string to remove illegal characters from</param>
        /// <returns></returns>
        public static string RemoveIllegalUrlCharacters(string input)
        {
            //input = input.Replace(" ", "");
            //input = input.Replace("„", "\"");
            //input = input.Replace("“", "\"");
            //input = input.Replace(".", "");
            //input = input.Replace(",", "");
            //input = input.Replace("+", "");
            //input = input.Replace("[", "");
            //input = input.Replace("]", "");
            //input = input.Replace("'", "");
            //input = input.Replace("=", "");
            //input = input.TrimStart('_');
            input = input.Trim(); 
            int index = Microsoft.SharePoint.Utilities.SPUrlUtility.IndexOfIllegalCharInUrlLeafName(input);
            while (index >= 0)
            {
                input = input.Remove(index, 1);
                index = Microsoft.SharePoint.Utilities.SPUrlUtility.IndexOfIllegalCharInUrlLeafName(input);
            }
            
            return input;
        }
    }
}
